import Taro, { Component } from '@tarojs/taro'
import { View, Text, Image, Picker, Swiper, SwiperItem } from '@tarojs/components'
import {AtForm,AtInput} from 'taro-ui'
import './updateLabel.scss'
import { $redirectTo } from '../../../global';
import reactMixin from 'react-mixin';
import myJs from './updateLabelJs.js'
import app from '../../../main.js'

export default class UpdateLabel extends Component {
    config = {
        navigationBarTitleText: '编辑标签'
    }
    constructor () { 
        super(...arguments); 
        this.state = this.getData(); 
    }
    init() {
        console.log(this.$router.params)
    }
    // save=()=>{
    //     app.redirectTo('../patientchoose/patientchoose');
    // }
    createLabel(){
        var me = this;
        var data = {};
        let ids='';
        for(let val of this.state.label.items){
            ids+=(val.id+',');
        }
        console.log('粗糙得ids：'+ids);
        data.label_name=this.state.label_name;
        data.ids=ids.substr(0,ids.length-1);
        console.log('data得ids：'+data.ids);
        
        if(this.$router.params.id==='0'){ 
            app.post("web/patientlabel/save", data, function(res) {
                console.log(res);
            });
        }else{
            data.id=this.$router.params.id;
            console.log('整个data:');
            console.log(data);
            app.post("web/patientlabel/save", data, function(res) {
                console.log(res);
                me.redirectTo('../patientchoose/patientchoose');
            });
        }
    
      }
    render () {
        return (
            <View className='updateLabel'>
                <AtForm>
                <AtInput
                        name='value'
                        type='text'
                        placeholder='请输入标签'
                        value={this.state.label.name}
                        onChange={this.handleChange.bind(this,'label.name')}
                    />
                </AtForm>
                <View className=' class_0' onClick={this.createLabel.bind(this)}>
                    <Text className=' class_1'>保存</Text>
                </View>
            </View>
        );
    }
}
reactMixin.onClass(UpdateLabel,myJs);